package com.jk.service.Impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jk.dao.StaffDao;
import com.jk.entity.StaffEntity;
import com.jk.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author mhj
 * @version 1.0
 * @description: 马辉杰
 * @date 2022/11/2 15:21
 */
@Service
public class StaffServiceImpl implements StaffService {

    @Autowired
    private StaffDao staffDao;


    @Override
    public List<StaffEntity> staffFindAll(StaffEntity staffEntity) {
        QueryWrapper<StaffEntity> wapper = new QueryWrapper<StaffEntity>();
        wapper.like(staffEntity.getStaffName() !=null && staffEntity.getStaffName()!="","staffName",staffEntity.getStaffName());//模糊查
        List<StaffEntity> list = staffDao.selectList(wapper);
        return list;
    }

    @Override
    public int staffcount() {
        QueryWrapper<StaffEntity> wrapper = new QueryWrapper<>();
        Integer integer = staffDao.selectCount(wrapper);
        return integer;
    }


    @Override
    public void addstaff(StaffEntity staffEntity) {
        if(staffEntity.getId()!=null){
            staffDao.updateById(staffEntity);
        }else{
            StaffEntity staffnumber=staffDao. stafforder();
            Integer staffnumber1 = staffnumber.getStaffnumber();

            staffEntity.setStaffnumber(staffnumber1+1);
            staffDao.addstaff(staffEntity);
        }
    }

    @Override
    public StaffEntity stafffinfByid(Integer id) {
        StaffEntity staffEntity = staffDao.selectById(id);
        return staffEntity;
    }

    @Override
    public void stafffDelByid(Integer id) {
        staffDao.deleteById(id);
    }


}
